package com.enqualcomm.kids.mvp.register;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.enqualcomm.kids.R;
import com.enqualcomm.kids.activities.RegisterActivity;
import com.enqualcomm.kids.view.BasePager;

public class RegisterStep3Pager extends BasePager implements OnClickListener {

	private View next_step_btn;
	private EditText register_password_et;

	public RegisterStep3Pager(Context context) {
		super(context);
	}

	@Override
	public View initView() {
		View root = View.inflate(ct, R.layout.pager_register_step3, null);
		next_step_btn = root.findViewById(R.id.next_step_btn);
		next_step_btn.setOnClickListener(this);
		
		register_password_et = (EditText) root.findViewById(R.id.register_password_et);
		register_password_et.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}
			
			@Override
			public void afterTextChanged(Editable s) {
				String inputPassword = s.toString().trim();
				if (inputPassword.length()>5) {//密码长度 6-16 位，输入框已经限制最长为16
					next_step_btn.setEnabled(true);
				}else {
					next_step_btn.setEnabled(false);
				}
			}
		});
		 
		return root;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.next_step_btn:
			String password = register_password_et.getText().toString().trim();
			InputMethodManager intputManager = (InputMethodManager)ct.getSystemService(Context.INPUT_METHOD_SERVICE);
			intputManager.hideSoftInputFromWindow(register_password_et.getWindowToken(), 0);
			next_step_btn.setEnabled(false);
			((RegisterActivity)ct).nextPage(3,password);
			break;

		default:
			break;
		}
		
	}
	
	@Override
	public void clear(){
		register_password_et.setText("");
	}
	public void setBtnEnable(boolean enable){
		next_step_btn.setEnabled(enable);
	}

}
